<template>
  <div class="app-container">
      <div class="filter-container">
        <el-input clearable v-model="search.number" placeholder="采购编号" style="width: 170px;"></el-input>
        
        <el-date-picker v-model="search.daterange" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="margin-left:10px;">
        </el-date-picker>
        <el-button type="primary" icon="el-icon-search" @click="searchClick()" style="margin-left:10px;">查询</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" 
      border fit highlight-current-row stripe 
      style="width: 100%">
      <el-table-column align="center" label="序" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row._id }}</span>
        </template>
      </el-table-column>
     <el-table-column  min-width="100" align="center" label="采购编号">
        <template slot-scope="scope">
          <span>{{ scope.row.purchasenumber }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="采购渠道">
        <template slot-scope="scope">
          <span>{{ scope.row.purchasechannel }}</span>
        </template>
      </el-table-column>
      
      <el-table-column  min-width="100" align="center" label="供应商">
        <template slot-scope="scope">
          <span>{{ scope.row.supplier }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="具体车型">
        <template slot-scope="scope">
          <span>{{ scope.row.carname }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="付款阶段">
        <template slot-scope="scope">
          <span>{{ scope.row.paystage }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="支付通知书">
        <template slot-scope="scope">
          <span>{{ scope.row.paynotice }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="采购单价">
        <template slot-scope="scope">
          <span>{{ scope.row.price }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="制单人">
        <template slot-scope="scope">
          <span>{{ scope.row.guider }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="备注">
        <template slot-scope="scope">
          <span>{{ scope.row.remark }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="日期">
        <template slot-scope="scope">
          <span>{{ scope.row.createtime | parseTime('{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="操作"  width="520" fixed="right">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="rowPrepayClick(scope.row.id)">预付款</el-button>
          <el-button type="primary" size="small" @click="rowEntryClick(scope.row.id)">入库</el-button>
          <el-button type="primary" size="small" @click="rowFixhistoryClick(scope.row.id)">付款</el-button>
          <el-button type="danger" size="small" @click="rowRefundClick(scope.row.id)">退货</el-button>
          <el-button type="primary" size="small" @click="rowDetailsClick(scope.row.id)">详情</el-button>
          
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.rows" @pagination="getList" />


<!-- 预付款 -->
<el-dialog :title="dialogPrepay.title" :visible.sync="dialogPrepay.visible"  width="700px">
    <div class="ci">
        <div class="bill" ref="prepaybill">
            <div class="item">1、摘要：支付******供应商车款 已支付</div>
            <div class="item">2、科目：</div>
            <div class="item">借1：113200n 预付账款-***单位  金额=23409.00元</div>
            <div class="item">贷1：113300n 中国银行 36月按揭贷款 金额=360000.00元</div>
            <div class="item">贷2：融资支付 210100n 金额=360000.00元</div>
            <div class="item">贷3：厂家返利支付， 1133 单位：**** 金额=360000.00元</div>
        </div>
        
    </div>
    <div slot="footer" class="dialog-footer">
        <el-button @click="dialogPrepay.visible = false">取 消</el-button>
        <el-button type="primary" @click="dgPrepayPrintClick()" :loading="dialogPrepay.saveloading">打 印</el-button>
        <el-button type="primary" @click="dgPrepaySaveClick()" :loading="dialogPrepay.saveloading">保 存</el-button>
    </div>
</el-dialog>
<!-- end 预付款 -->

  </div>
</template>

<script>

import { deepClone,parseTime } from '@/utils'
import * as auth from '@/utils/auth'
import * as vehicleApi from '@/api/finance/vehicle'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import Print from '@/utils/print'


export default {
  name: 'IncomeInfo',
  components: { Pagination },
  data(){
    return{
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        rows: 20,
        number:'',
      },
      search:{
        number:'',
      },
      dialogPrepay:{
          visible:false,
          saveloading:false,
          title:'预付款',
          data:{

          }
      }
    }
  },
  created(){
      var that=this;
      that.searchClick();
  },
  mounted(){

  },
  filters:{
    parseSettleType(val){
       return ['','收益','提现'][val];
    }
  },
  methods: {
    getList(){
      var that=this;
      that.listLoading = true;
      
      vehicleApi.getPurchaseList(that.listQuery).then(res=>{
         if(res.data && res.data.items){
            that.list=[...res.data.items.map((item,index)=>{
              item._id=index+1;
              return item;
            })];
            that.listLoading = false;
            that.total=res.data.total || 0;
         }
      })
    },
    searchClick(){
      var that=this;
      that.listQuery.page=1;
      that.listQuery.number=that.search.number.trim();
      that.getList();
    },
    rowPrepayClick(id){
        var that=this;
        var selectItem=that.list.filter(o=>o.id==id)[0];
        that.dialogPrepay.visible=true;
    },
    dgPrepaySaveClick(){

    },
    dgPrepayPrintClick(){
        var that=this;
        //that.$print(that.$refs['prepaybill']);
        new Print(that.$refs['prepaybill']).Start();
    }
    
  }
}
</script>
<style scoped>

</style>
